from MySQLdb import connect

class DBHandler:
		def __init__(self, host, user, passwd, database):
				self.host = host
				self.user = user
				self.passwd = passwd
				self.database = database

		def connect(self):
				self.db = connect(host=self.host, user=self.user, passwd=self.passwd, db=self.database)

		def close(self):
				self.cursor.close()

		def insertRss(self, rsspath, userid):
				self.cursor = self.db.cursor()
				self.cursor.execute("insert into rss_table(rsspath, userid) values ('%s', '%s')"  % (rsspath, userid))

		def insertUser(self, userid, passwd, rsspath, usertype):
				self.cursor = self.db.cursor()
				self.cursor.execute("insert into user_table(userid, passwd, rsspath, usertype) values ('%s','%s','%s','%s')"  % (userid, passwd, rsspath, usertype))

		def insertPost(self, path, title, userid):
				regdate = strftime('%Y%m%d%s')
				regtime = strftime('%s')
				self.cursor = self.db.cursor()
				self.cursor.execute("insert into post_table(postpath, rsspathid, posttitle, regdate, regtime) values ('%s','%s','%s','%s','%s')"  % (postpath, rsspathid, posttitle, regdate, regtime))

		def getRssPathList(self):
				self.cursor = self.db.cursor()
				self.cursor.execute('select rsspath from rss_table')

				rsspathlist = self.cursor.fetchall()
				return rsspathlist

		def getPostList(self):
				self.cursor = self.db.cursor()
				self.cursor.execute('select * from post_table')
				
				postlist = self.cursor.fetchall()
				return postlist
			
if __name__ == '__main__':
	dbHandler = DBHandler('localhost', 'dada', '9t6e5q', 'rssproject')
	dbHandler.connect()
	dbHandler.insertUser('dada', '9t6e5q', 'http://kid.pe.kr/tt/rss', '1')
	dbHandler.close()